﻿using MusicExplorer.Common;
using MusicExplorer.ViewModel;
using MusicExplorer.ViewModel.Wrappers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using System.Windows.Input;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Items Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234233

namespace MusicExplorer.View
{
    /// <summary>
    /// A page that displays a collection of item previews.  In the Split App this page
    /// is used to display and select one of the available groups.
    /// </summary>
    public sealed partial class RepositoryPageView : Page
    {
        public RepositoryPageView()
        {
            InitializeComponent();
        }

        //async void m_navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        //{
        //    var navObj = (NavigationObject)e.NavigationParameter;
        //    DataContext = await RepositoryPageViewModel.CreateAsync<RepositoryPageViewModel>(navObj);
        //}

        #region NavigationHelper registration

        /// The methods provided in this section are simply used to allow
        /// NavigationHelper to respond to the page's navigation methods.
        /// 
        /// Page specific logic should be placed in event handlers for the  
        /// <see cref="GridCS.Common.NavigationHelper.LoadState"/>
        /// and <see cref="GridCS.Common.NavigationHelper.SaveState"/>.
        /// The navigation parameter is available in the LoadState method 
        /// in addition to page state preserved during an earlier session.
        #endregion

        private void OnGenreClick(object sender, ItemClickEventArgs e)
        {
            var entity = ((GenreWrapper)e.ClickedItem).Entity;
            var parent = (ViewModelBase)DataContext;
            var repository = ((RepositoryPageViewModel)DataContext).Repository;
            this.Frame.Navigate(typeof(TracksPageView), new NavigationObject(parent, entity, repository));
        }
    }
}
